<template>
  <dtDialog
    title="任务详情"
    :visible.sync="taskDetailVisible"
    :is-loading="loading"
    :footer-slot="true"
    @closeDialog="handleCancel"
  >
    <el-form
      ref="taskDetailForm"
      slot="content"
      :rules="taskDetailRules"
      :model="taskDetailTemp"
      label-position="right"
      label-width="100px"
    >
      <el-row :gutter="20">
        <el-col :span="12" :xs="24">
          <el-form-item label="任务名称" prop="jobName">
            <el-input v-model.trim="taskDetailTemp.jobName" autosize disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12" :xs="24">
          <el-form-item label="任务编码" prop="jobId">
            <el-input v-model.trim="taskDetailTemp.jobId" disabled />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12" :xs="24">
          <el-form-item label="任务生成方式" prop="generateType">
            <el-select v-model.trim="taskDetailTemp.generateType" style="width:100%" disabled>
              <el-option
                v-for="dict in dict.type.generateType"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12" :xs="24">
          <el-form-item label="推送方式" prop="syncStratey">
            <el-select v-model.trim="taskDetailTemp.syncStratey" style="width:100%" disabled>
              <el-option
                v-for="dict in syncStratey"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12" :xs="24">
          <el-form-item label="同步应用" prop="appName">
            <el-input v-model.trim="taskDetailTemp.appName" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12" :xs="24">
          <el-form-item label="同步信息类型" prop="dataType">
            <el-select v-model.trim="taskDetailTemp.dataType" style="width:100%" disabled>
              <el-option
                v-for="dict in dict.type.dataType"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12" :xs="24">
          <el-form-item label="推送类型" prop="operationType">
            <el-select v-model.trim="taskDetailTemp.operationType" style="width:100%" disabled>
              <el-option
                v-for="dict in dict.type.operationType"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12" :xs="24">
          <el-form-item label="推送数量" prop="syncCount">
            <el-input v-model.trim="taskDetailTemp.syncCount" disabled />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24" :xs="24">
          <el-form-item label="推送状态" prop="status">
            <el-select v-model.trim="taskDetailTemp.status" style="width:100%" disabled>
              <el-option
                v-for="dict in dict.type.status"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12" :xs="24">
          <el-form-item label="任务创建时间" prop="createTime">
            <el-input v-model.trim="taskDetailTemp.createTime" disabled />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24" :xs="24">
          <el-form-item label="失败原因" prop="failReason">
            <el-input v-model.trim="taskDetailTemp.failReason" disabled autosize
                      type="textarea" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="推送信息" prop="sourceData">
        <el-input v-model.trim="taskDetailTemp.sourceData" disabled autosize
                  type="textarea" />
        <!-- <el-input v-if="taskDetailTemp.dataType=='2'" v-model.trim="queryParams.orgName" placeholder="输入搜索组织名称" style="width:200px;" clearable @blur="getList" @keyup.enter.native="getList" />
        <el-input v-if="taskDetailTemp.dataType=='1'" v-model.trim="queryParams.userName" placeholder="输入搜索姓名" style="width:200px;" clearable @blur="getList" @keyup.enter.native="getList" />
        <dt-table
          v-if="taskDetailTemp.dataType=='2'"
          v-loading="loading"
          style="margin-top:10px;"
          :table-opts="tableOptsOrg"
          :is-show-column="false"
          :pagination-data="{
            total:totalOrg,
            queryParams:queryParams
          }"

          :is-column-search="false"
          @pagination="pagination"
        />
        <dt-table
          v-if="taskDetailTemp.dataType=='1'"
          v-loading="loading"
          style="margin-top:10px;"
          :table-opts="tableOptsPerson"
          :is-show-column="false"
          :pagination-data="{
            total:totalPerson,
            queryParams:queryParams
          }"

          :is-column-search="false"
          @pagination="pagination"
        /> -->
      </el-form-item>
    </el-form>
  </dtDialog>
</template>
<script>
import dataSynchronizationApi from '@/framework/api/datasync/dataSynchronization'

export default {
  dicts: ['dataType', 'operationType', 'generateType', 'status', 'orgLevel', 'orgCategory', 'sex', 'syncStratey'],
  data() {
    return {
      loading: false,
      taskDetailVisible: false,
      taskDetailTemp: {
        jobName: '',
        jobId: '',
        generateType: '',
        dataType: '',
        operationType: '',
        appName: '',
        createTime: '',
        syncCount: '',
        status: '',
        failReason: ''
      },
      taskDetailRules: {},
      tableOptsOrg: {
        indexTableCol: {
          label: '序号',
          width: 70
        },
        firstTableCol: {
          select: false
        },
        tableCol: [
          {
            prop: 'orgName',
            label: '组织名称',
            show: true
          },
          {
            prop: 'orgCode',
            label: '组织编码',
            show: true
          },
          {
            prop: 'orgLevel',
            label: '组织层级',
            show: true,
            type: 'dict',
            formatter: () => { return this.dict.type.orgLevel }
          },
          {
            prop: 'orgCategory',
            label: '部门类别',
            show: true,
            type: 'dict',
            formatter: () => { return this.dict.type.orgCategory }
          }
        ],
        tableData: []
      },
      tableOptsPerson: {
        indexTableCol: {
          label: '序号',
          width: 70
        },
        firstTableCol: {
          select: false
        },
        tableCol: [
          {
            prop: 'account',
            label: '账号',
            show: true
          },
          {
            prop: 'realName',
            label: '姓名',
            show: true
          },
          {
            prop: 'sex',
            label: '性别',
            show: true,
            type: 'dict',
            formatter: () => { return this.dict.type.sex }
          },
          {
            prop: 'phone',
            label: '电话',
            show: true
          },
          {
            prop: 'email',
            label: '邮箱',
            show: true
          },
          {
            prop: 'orgName',
            label: '组织',
            show: true
          },
          {
            prop: 'positionName',
            label: '岗位',
            show: true
          }
        ],
        tableData: []
      },
      totalOrg: 0,
      totalPerson: 0,
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        orgName: '',
        userName: ''
      },
      jobId: '',
      dataType: '',
      // 推送方式字典数据
      syncStratey: [
        { value: 1, label: 'MQ' },
        { value: 2, label: 'API' }
      ]
    }
  },
  methods: {
    handleCancel() {
      this.queryParams = {
        pageNo: 1,
        pageSize: 10,
        orgName: '',
        userName: ''
      }
    },
    openDialog(row) {
      this.taskDetailVisible = true
      this.jobId = row.jobId
      this.dataType = row.dataType
      this.getList(row)
    },
    pagination() {
      this.getList()
    },
    getList(row) {
      this.loading = true
      const id = {}
      if (row.jobId) {
        id.jobId = row.jobId
      } else {
        id.jobId = this.jobId
      }
      dataSynchronizationApi.detail({ ...id, ...this.queryParams }).then((res) => {
        this.taskDetailTemp = res.data
        // if (row.dataType == 1 || this.dataType == 1) {
        //   this.tableOptsPerson.tableData = res.data.sysUserList.rows
        //   this.totalPerson = res.data.sysUserList.totalRows
        //   this.loading = false
        // } else {
        //   this.tableOptsOrg.tableData = res.data.orgList.rows
        //   this.totalOrg = res.data.orgList.totalRows
        //   this.loading = false
        // }
      })
    }
  }
}
</script>
<style>

</style>
